package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.PeopleNum;
import com.ruoyi.system.mapper.PeopleNumDao;
import com.ruoyi.system.service.PeopleNumService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class PeopleNumServiceImpl extends ServiceImpl<PeopleNumDao, PeopleNum> implements PeopleNumService {
    @Override
    public int insertPeopleNum(PeopleNum peopleNum) {
        PeopleNum pn = new PeopleNum();
        pn.setScenic(peopleNum.getScenic());
        pn.setMaxNum(peopleNum.getMaxNum());
        pn.setPresentNum(peopleNum.getPresentNum());
        pn.setThreeDays(peopleNum.getThreeDays());
        return baseMapper.insert(pn);
    }

    @Override
    public int deletePeopleNumById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public int updatePeopleNum(PeopleNum peopleNum) {
        LambdaQueryWrapper<PeopleNum> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PeopleNum::getId, peopleNum.getId());
        PeopleNum pn = baseMapper.selectOne(lqw);
        if (pn == null){
            throw new RuntimeException("PeopleNum not found");
        }
        pn.setScenic(peopleNum.getScenic());
        pn.setMaxNum(peopleNum.getMaxNum());
        pn.setPresentNum(peopleNum.getPresentNum());
        pn.setThreeDays(peopleNum.getThreeDays());
        return baseMapper.updateById(pn);
    }

    @Override
    public PeopleNum selectPeopleNumById(Long id) {
        return baseMapper.selectById(id);
    }

    @Override
    public List<PeopleNum> selectPeopleNumList() {
        //todo
        return null;
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
